package main.chapter3

interface IA {
    fun x(): Int = 0
}

interface IB {
    fun x(): Int = 1
}

abstract class BaseA {
    open fun x(): Int = 2
}

class ClassC(var y: Int = 0) : BaseA(), IA, IB {
    //解决方法冲突问题
    override fun x(): Int {
        return when {
            y < 0 -> super<IA>.x()
            y > 0 -> super<IB>.x()
            else -> super<BaseA>.x()
        }
    }
}

fun main(args: Array<String>) {
    val classC1 = ClassC()
    val classC2 = ClassC(-1)
    val classC3 = ClassC(1)
    println(classC1.x())
    println(classC2.x())
    println(classC3.x())
}